﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace KTX
{
    public partial class frmHopDong : DevExpress.XtraEditors.XtraForm
    {
        public frmHopDong()
        {
            InitializeComponent();
        }

        Data.QLKTXEntities db = new Data.QLKTXEntities();
        private void barThem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var f = new frmThemHopDong();
            f.ShowDialog();
        }

        private void barDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void barXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.hopDongBindingSource.RemoveCurrent();
        }

        private void barSua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (hopDongBindingSource.Current != null)
            {
                var f = new frmThemHopDong((Data.HopDong)hopDongBindingSource.Current);
                f.ShowDialog();
            }
        }

        private void barLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            db.SaveChanges();
        }

        private void barIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var report = new BaoCao.xDanhSachHopDong();
            BindingSource bs = (BindingSource)report.DataSource;
            bs.DataSource = hopDongBindingSource.List;
            report.ShowPreviewDialog();
        }

        private void frmHopDong_Load(object sender, EventArgs e)
        {
            spinEdit1.Value = DateTime.Now.Year;
            lopBindingSource.DataSource = db.Lop;
            dayNhaBindingSource.DataSource = db.DayNha;
            hopDongBindingSource.DataSource = db.HopDong;
        }

        private void hopDonggridView_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Clicks==2 && this.hopDongBindingSource.Current!=null)
            {
                var f = new frmThemHopDong((Data.HopDong)this.hopDongBindingSource.Current);
                f.ShowDialog();
            }
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            var malop= (int)gridLookUpEdit1.EditValue;
            var daynha= (int)gridLookUpEdit2.EditValue;
            hopDongBindingSource.DataSource = db.HopDong.Where(p => p.SinhVien.MaLop == malop && p.Phong.MaNha == daynha);
        }
    }
}